/**
***	
***************************************************************
***	 	Copyright (c) 2017 Queclink Ltd.   
***
*** 		flash_cmn.h
*** 		dev mx25f 
*** 		sean.guo
***		2017-06-29
***		APP LEVEL file
***		FLASH 选型操作通用文件
**************************************************************
***
**/
#ifndef _FLASH_CMN_H_
#define _FLASH_CMN_H_

#ifdef __cplusplus
	extern "C"{
#endif

#define		SIZE_K(x)		(1024ul*x)
#define		SIZE_M(x)		(1024ul*1024*x)
      
/**	芯片属性**/
typedef struct
{
	char			name[16];		/**  芯片名称**/
	unsigned int 	capacity;			/**	芯片容量**/
	unsigned int   block_size;		/**	块大小	**/
	unsigned int   sector_size;		/**  扇区大小**/
}fchip_info_t;
      

/**	操作接口函数**/
typedef struct
{
	int 			(*init)(void);											/**初始化**/
	int 			(*read)(unsigned int addr,void*buf,unsigned int len);		/**读操作**/
	int 			(*write)(unsigned int addr,void*buf,unsigned int len);		/**写操作**/
	int 			(*erase_chip)(void);									/**芯片擦除**/
	int 			(*erase_sector)(unsigned int addr);						/**扇区擦除**/
	int 			(*erase_block)(unsigned int addr);						/**扇区擦除**/
	unsigned char (*status)(void);										/**flash 操作状态**/
}fdrv_adp_t;

typedef void (*p_fun_flash_sector_check_t)(unsigned int addr);
		
extern p_fun_flash_sector_check_t p_flash_sector_check;
extern const unsigned int chip_erase_time;
extern const unsigned int block_erase_time;
extern const unsigned int sector_erase_time;
extern const unsigned int page_program_time;
extern const unsigned char manufacturer_id;

extern const fdrv_adp_t		fadp;
extern const fchip_info_t 	fchip;

int 			flash_dev_init(void);
int 			flash_dev_read(unsigned int addr,void*buf,unsigned int len);
int 			flash_dev_write(unsigned int addr,void*buf,unsigned int len);
int 			flash_dev_erase_chip(void);
int				flash_dev_erase_block(unsigned int addr);
int 			flash_dev_erase_sector(unsigned int addr);
unsigned char  	flash_dev_status(void);
void            flash_if_add_sector_check_node(unsigned int addr);

#ifdef __cplusplus
	}
#endif

#endif
/**	END FO FILE **/


